import { ElMessage } from 'element-plus';
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
//全局进度条的配置
NProgress.configure({
    easing: 'ease', // 动画方式
    speed: 1000, // 递增进度条的速度
    showSpinner: false, // 是否显示加载ico
    trickleSpeed: 200, // 自动递增间隔
    minimum: 0.3, // 更改启动时使用的最小百分比
    parent: 'body', //指定进度条的父容器
  })
  
// import { useRouter } from 'vue-router'
// import { userStore } from "@/store/modules/user"
import {removestrange} from '@/Hook/removestrong.ts'
// 获取项目路由对象
// let router = useRouter();
// 获取项目pina对象
// const user = userStore()
// 创建请求实例 
interface typeData {
    code: number,
    message: string,
    data?: any
}
let loading: any;
const Service = axios.create({
    timeout: 50000,
    baseURL: "/api",
})
// 请求拦截
Service.interceptors.request.use((config) => {
    // let token = localStorage.getItem('token')
    // if (token) {
    //     config.headers.authorization = token
    // }
    config.headers["content-type"] = 'multipart/form-data; boundary=----WebKitFormBoundary7TMYhSONfkAM2z3a'
    NProgress.start()
    return config
}, () => {

})
// 响应拦截
Service.interceptors.response.use(res => {
    NProgress.done()
    const data: typeData = res.data
    if (data.code == 200) {
        return data
    } else {
        return data
    }
}, err => {

  return err
    loading.close()
})

interface configType {
    url: string,
    data?: any,
    headers?: any
}
// 暴露请求方法
// post get put delete
export const post = (config: configType) => {
    return Service({
        ...config,
        method: "post",
        params: config.data
    })
}
export const get = (config?: configType) => {
    return Service({
        ...config,
        method: "get",
        params: config?.data
    })
}
export const put = (config: configType) => {
    return Service({
        ...config,
        method: "put",
        data: JSON.stringify(config.data)
    })
}
export const patch = (config: configType) => {
    return Service({
        ...config,
        method: "patch",
        data: config.data
    })
}
// 例子:delete请求放式没有data参数传递 url?id=1&type=2
export const del = (config: configType) => {
    return Service({
        ...config,
        method: "delete",
    })
}

